1
2
3
4
5 package com.jguild.jrpm.io.datatype;
6
7 import com.jguild.jrpm.io.IndexEntry;
8 import com.jguild.jrpm.io.constant.RPMIndexType;
9
10 import org.apache.log4j.Logger;
11
12 import java.io.DataInputStream;
13 import java.io.IOException;
14
15 /***
16 * A representation of a rpm 64 byte integer array data object
17 *
18 * @author kuss
19 */
20 public class INT64 implements DataTypeIf {
21
22 private static final Logger logger = Logger.getLogger(INT64.class);
23
24 private long[] data;
25
26 private long size;
27
28 INT64(long[] data) {
29 this.data = data;
30 size = data.length * 8;
31 }
32
33 /***
34 * Get the rpm int64 array as a java long array
35 *
36 * @return An array of longs
37 */
38 public long[] getData() {
39 return data;
40 }
41
42
43
44
45 public Object getDataObject() {
46 return data;
47 }
48
49
50
51
52 public RPMIndexType getType() {
53 return RPMIndexType.INT64;
54 }
55
56 /***
57 * Constructs a type froma stream
58 *
59 * @param inputStream
60 * An input stream
61 * @param indexEntry
62 * The index informations
63 * @return The size of the read data
64 * @throws IOException
65 * if an I/O error occurs.
66 */
67 public static INT64 readFromStream(DataInputStream inputStream,
68 IndexEntry indexEntry) throws IOException {
69 if (indexEntry.getType() != RPMIndexType.INT64) { throw new IllegalArgumentException(
70 "Type <" + indexEntry.getType() + "> does not match <"
71 + RPMIndexType.INT64 + ">"); }
72
73 long[] data = new long[(int) indexEntry.getCount()];
74
75 for (int pos = 0; pos < indexEntry.getCount(); pos++) {
76 data[pos] = inputStream.readLong();
77 }
78
79 INT64 int64Object = new INT64(data);
80
81 if (logger.isDebugEnabled()) {
82 logger.debug(int64Object.toString());
83 }
84
85
86
87
88 return int64Object;
89 }
90
91
92
93
94 public boolean isArray() {
95 return true;
96 }
97
98
99
100
101 public long getElementCount() {
102 return data.length;
103 }
104
105
106
107
108 public long getSize() {
109 return size;
110 }
111
112
113
114
115 public Object get(int i) {
116 return new Long(data[i]);
117 }
118
119
120
121
122 public String toString() {
123 StringBuffer buf = new StringBuffer();
124
125 if (data.length > 1) {
126 buf.append("[");
127 }
128
129 for (int pos = 0; pos < data.length; pos++) {
130 buf.append(data[pos]);
131
132 if (pos < (data.length - 1)) {
133 buf.append(", ");
134 }
135 }
136
137 if (data.length > 1) {
138 buf.append("]");
139 }
140
141 return buf.toString();
142 }
143 }